# @author zfd
# @date 2022年12月13日 17:12
# @desc 检查文件是否存在 不存在则创建
import os

file = 'students.txt'

# if not os.path.exists(file):
#     with open(file, 'w') as f:
#         f.write('')

students = []
with open(file, 'r') as f:
    lines = f.readlines()
    for line in lines:
        students.append(dict(eval(line)))
students.sort(key=lambda x: x['C'], reverse=False)
print('%-10s %-10s %-10s %-10s %-10s %-10s' % ('ID', 'Name', 'C','Java', 'Python','总成绩'))
print('%-10s %-10s %-10s %-10s %-10s %-10s' % ('ID', 'Name', 'C','Java', 'Python','总成绩'))
# print('%.3f' % 3.1415926)
#
# print('ID '.ljust(10), '名字 '.ljust(10), 'C成绩 '.ljust(10), 'Java成绩 '.ljust(10), 'Python成绩 '.ljust(10),
#       '总成绩'.ljust(10))

for stu in students:
    print('%-10d %-10s %-10.3f %-10.3f %-10.3f %-10.3f' % (stu['id'], stu['name'], stu['C'], stu['Java'], stu['Python'],
                                                     stu['C'] + stu['Java'] + stu['Python']))
